﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Users_MyApplyInfo : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IDCard != null)
        {
            if (!Page.IsPostBack)
            {
                bindDataTable();
            }
        }
    }
    private void bindDataTable()
    {
        DataTable dt = Exam.getApplyInfosByIdCard(IDCard);
        if (dt.Columns.Contains("ApplyStateCHN"))
            dt.Columns.Remove("ApplyStateCHN");
        dt.Columns.Add("ApplyStateCHN");
        foreach (DataRow dr in dt.Rows)
        {
            dr["ApplyStateCHN"] = int.Parse(dr["ApplyState"].ToString()) > 1 ? "已完成" : "未完成";
        }
        gv.DataSource = dt;
        gv.DataBind();
    }

    protected void operatUrl_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HyperLink hlOperateUrl = (HyperLink)e.Row.FindControl("operatUrl");
            string applyState = gv.DataKeys[e.Row.RowIndex].Values[1].ToString().Trim();
            string applyId = gv.DataKeys[e.Row.RowIndex].Values[0].ToString().Trim();
            string orderId = gv.DataKeys[e.Row.RowIndex].Values[2].ToString().Trim();
            
            if (applyState == "2")
            {
                hlOperateUrl.Visible = false;
            }
            else if (applyState == "1")
            {
                hlOperateUrl.NavigateUrl = BSUtility.mainUrl + "BM/BM4.aspx?OrderID=" + orderId;
            }
            else
            {
                string emNum = gv.DataKeys[e.Row.RowIndex].Values[5].ToString().Trim();
                string emYear = gv.DataKeys[e.Row.RowIndex].Values[4].ToString().Trim();
                string emId = gv.DataKeys[e.Row.RowIndex].Values[3].ToString().Trim();

                hlOperateUrl.NavigateUrl = BSUtility.mainUrl + "BM/BM1.aspx?EmID=" + emId + "&EmYear=" + emYear + "&EmNum=" + emNum;
            }
        }
    }
}